﻿/* Copyright (c) 2010 EPiServer AB
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
using EPiServer.Core;
using EPiServer.Municipality.Extensions;

namespace EPiServer.Municipality.Templates.Units {
    /// <summary>
    /// 
    /// </summary>
    /// <remarks></remarks>
    /// <example></example>
    public partial class Contact : UserControlBase {
        /* *******************************************************************
		 *  Properties
		 * *******************************************************************/
        #region public PageData CurrentData
        /// <summary>
        /// Get/Sets the CurrentData of the Contact
        /// </summary>
        /// <value></value>
        public PageData CurrentData {
            get {
                return _currentData ?? CurrentData;
            }
            set {
                _currentData = value;
            }
        }

        private PageData _currentData;
        #endregion
        #region public string Name
        /// <summary>
        /// Gets the Name of the Contact
        /// </summary>
        /// <value></value>
        public string Name {
            get {
                if (CurrentData.IsValue("ContactEmail"))
                    return String.Format("<a class=\"email\" href=\"mailto:{0}\" >{1}</a>", CurrentData["ContactEmail"], CurrentData.PageName);
                return CurrentData.PageName;
            }
        }
        #endregion
        #region public string Title
        /// <summary>
        /// Gets the Title of the Contact
        /// </summary>
        /// <value></value>
        public string Title {
            get {
                if (CurrentData.IsValue("ContactTitle"))
                    return ", " + CurrentData["ContactTitle"];
                return string.Empty;
                
            }
        }
        #endregion
        #region public string Department
        /// <summary>
        /// Gets the Department of the Contact
        /// </summary>
        /// <value></value>
        public string Department {
            get {
                if (CurrentData.IsValue("ContactDepartment"))
                    return "<br />" + CurrentData["ContactDepartment"];
                return String.Empty;
            }
        }
        #endregion
        #region public string PhoneGeneral
        /// <summary>
        /// Gets the PhoneGeneral of the Contact
        /// </summary>
        /// <value></value>
        public string PhoneGeneral {
            get {
                if (CurrentData.IsValue("ContactPhoneNumberGeneral"))
                    return "<br />" + Translate("/municipality/templates/contactcard/phonegeneral") + CurrentData["ContactPhoneNumberGeneral"];
                return String.Empty;
            }
        }
        #endregion
        #region public string PhoneDirect
        /// <summary>
        /// Gets the PhoneDirect of the ContactCard
        /// </summary>
        /// <value></value>
        public string PhoneDirect {
            get {
                if (CurrentData.IsValue("ContactPhoneNumberDirectly"))
                    return "<br />" + Translate("/municipality/templates/contactcard/phonedirect") + CurrentData["ContactPhoneNumberDirectly"];
                return String.Empty;
            }
        }
        #endregion
        #region public string PhoneMobile
        /// <summary>
        /// Gets the Phonemobile of the Contact
        /// </summary>
        /// <value></value>
        public string PhoneMobile {
            get {
                if (CurrentData.IsValue("ContactPhoneNumberMobile"))
                    return "<br />" + Translate("/municipality/templates/contactcard/phonemobile") + CurrentData["ContactPhoneNumberMobile"];
                return String.Empty;
            }
        }
        #endregion
        #region public string Telefax
        /// <summary>
        /// Gets the Telefax of the Contact
        /// </summary>
        /// <value></value>
        public string Telefax {
            get {
                if (CurrentData.IsValue("ContactTelefax"))
                    return "<br />" + Translate("/municipality/templates/contactcard/telefax") + CurrentData["ContactTelefax"];
                return String.Empty;
            }
        }
        #endregion
        #region public string Address
        /// <summary>
        /// Gets the Address of the Contact
        /// </summary>
        /// <value></value>
        public string Address {
            get {
                string strAddress = String.Empty;
                if (CurrentData.IsValue("ContactStreetAddress"))
                    strAddress = "<br />" + CurrentData["ContactStreetAddress"];
                if (CurrentData.IsValue("ContactBoxAddress"))
                    strAddress += "<br />" + CurrentData["ContactBoxAddress"];
                if (CurrentData.IsValue("ContactPostalNumber") || CurrentData.IsValue("ContactAddress"))
                    strAddress += "<br />" + CurrentData["ContactPostalNumber"] + " " + CurrentData["ContactAddress"];

                return strAddress + "<br />";
            }
        }
        #endregion
        #region public string Information
        /// <summary>
        /// Gets the Information of the Contact
        /// </summary>
        /// <value></value>
        public string Information {
            get {
                if (CurrentData.IsValue("ContactInformation"))
                    return "<p>" + CurrentData["ContactInformation"] + "</p>";
                return String.Empty;
            }
        }
        #endregion
        #region public string Link
        /// <summary>
        /// Gets the Link of the Contact
        /// </summary>
        /// <value></value>
        public string Link {
            get {
                if (CurrentData.IsValue("ContactLink") && CurrentData.IsValue("ContactLinkText")) {
                    if (CurrentData["ContactLink"].ToString().ToLower().IndexOf("://") > -1)
                        return String.Format("<span class=\"external\"><a href=\"{0}\" >{1}</a></span>", CurrentData["ContactLink"], CurrentData["ContactLinkText"]);
                    return String.Format("<a href=\"{0}\" >{1}</a>", CurrentData["ContactLink"], CurrentData["ContactLinkText"]);
                }
                return String.Empty;
            }
        }
        #endregion
        
        /* *******************************************************************
        * Methods
        * *******************************************************************/
        #region override protected void OnInit(EventArgs e)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        override protected void OnInit(EventArgs e) {
            InitializeComponent();
            base.OnInit(e);
        }
        #endregion
        #region private void InitializeComponent()
        /// <summary>
        /// 
        /// </summary>
        private void InitializeComponent() {
            Load += Page_Load;
        }
        #endregion
        /* *******************************************************************
        *  Event methods 
        * *******************************************************************/
        #region protected void Page_Load(object sender, EventArgs e)
        /// <summary>
        /// This method is called when the Page's Load event has been fired.
        /// </summary>
        /// <param name="sender">The <see cref="object"/> that fired the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> of the event.</param>
        protected void Page_Load(object sender, EventArgs e) {
        }
        #endregion
    }
}